package com.example.fx.order

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.*
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class OrderViewModel:BaseViewModel() {
    val getPreSuccess = MutableLiveData<GetPreOrderEntityResult>()
    val getPreFail = MutableLiveData<String>()
    fun getPreOrder(preOrderNo:String){
        viewModelScope.launch {
            try {
                getPreSuccess.value = apiService.getPreOrder(preOrderNo)
            }catch (e:Exception){
                getPreFail.value = e.message
            }
        }
    }
    //创建订单
    val createSuccess = MutableLiveData<CreateOrderEntityResult>()
    val createFail = MutableLiveData<String>()
    fun createOrder(body:CreateOrderParamEntity){
        viewModelScope.launch {
            try {
                createSuccess.value = apiService.createOrder(body)
            }catch (e:Exception){
                createFail.value = e.message
            }
        }
    }
    //支付
    val paySuccess = MutableLiveData<PayEntityResult>()
    val payFail = MutableLiveData<String>()
    fun pay(body:PayParamEntity){
        viewModelScope.launch {
            try {
                paySuccess.value = apiService.pay(body)
            }catch (e:Exception){
                payFail.value = e.message
            }
        }
    }

    val listSuccess = MutableLiveData<OrderEntityResult>()
    val listFail = MutableLiveData<String>()
    fun orderlist(type:String,page:Int,limit:Int){
        viewModelScope.launch {
            try {
                listSuccess.value = apiService.orderlist(type, page, limit)
            }catch (e:Exception){
                listFail.value = e.message
            }
        }
    }

}